package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;
import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareUserInfoEntity;
import com.sgb.knowledgeshare.view.activity.ShareUserActivity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by fq on 2020/9/11 0011
 * Description： 单个用户中心界面
 */
public class ShareUserModel extends ViewModel {
    ShareUserActivity activity;
    public void setActivity(ShareUserActivity shareUserActivity) {
        activity = shareUserActivity;
    }

    //获取用户信息
    public void getUserHomePage(String usreid) {
        Map map = new HashMap();
        map.put("userNo", usreid);
        DialogHelper.showProgressDialog(activity, null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getUserHomePage(map).enqueue(new ICallBack<BaseEntity<ShareUserInfoEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ShareUserInfoEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    activity.setUserData(data.getData());
                } else {
                    MToast.showToast(activity, data.getMsg());
                }
            }
        });
    }

    //  关注和取消关注接口
    public void getFens(String userid) {
        Map map = new HashMap();
        map.put("userNo", userid);
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    activity.UpdataUserIfno();
                } else {
                    MToast.showToast(activity, data.getMsg());
                }
            }
        });
    }


}
